﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using BluePortal.Medias.Core;
using BluePortal.Framework;

namespace BluePortal.QuikStart
{
    public partial class Browse : System.Web.UI.Page
    {
        Guid vidSelected;
        protected void Page_Load(object sender, EventArgs e)
        {
            IEnumerable<Media> query;
            VideoList1.mode = BluePortal.QuikStart.UserControls.VideoListMode.Default;
            if (!Page.IsPostBack)
            {
                //if (Request.QueryString["tag"] != null)
                //{
                //    lbBrowse.Text = "Video for tag : " + Request.QueryString["tag"];
                //    query = from fall in BluePortal.QuikStart.Adapter.VideoAdapter.instance.FindAllWithFavoriesWithPlaylistWithViewCount(User.Identity.Name, null)
                //            from vt in fall.VideoTags
                //            where vt.Tag.TagName == Request.QueryString["tag"]
                //            select fall;
                //}
                //else
                //    if (Request.QueryString["user"] != null)
                //    {
                //        lbBrowse.Text = "Video for user : " + Request.QueryString["user"];
                //        query = from fall in BluePortal.QuikStart.Adapter.VideoAdapter.instance.FindAllWithFavoriesWithPlaylistWithViewCount(User.Identity.Name, null)
                //                where fall.Owner == Request.QueryString["user"]
                //                select fall;
                //    }
                //    else
                //    {
                //        query = BluePortal.QuikStart.Adapter.VideoAdapter.instance.FindAllWithFavoriesWithPlaylistWithViewCount(User.Identity.Name, null);
                //    }
                
                
                //query = new BCMedia().FindAllWithFavoriesWithPlaylistWithViewCount(User.Identity.Name, null);
                //@todo 
                query = new BCMedia().FindAll(new FindParameters() { Count = 50});
                //@todo

                VideoList1.VideosList = query;

                //Extract Categories
                //var queryCat = BluePortal.QuikStart.Adapter.VideoCategoryAdapter.instance.ExtractCategories(query);
                //rpCategories.DataSource = queryCat;
                //rpCategories.DataBind();

                //Extract TagClound on Query
                var queryTag = new BCTag().FindAllForTagCloud();
                Cloud1.DataSource = queryTag;
                Cloud1.DataBind();

            }

            //if (Request.QueryString["vid"] != null)
            //{
            //    vidSelected = new Guid(Request.QueryString["vid"]);
            //    ViewState["vidSelected"] = vidSelected;
            //}
            //else
            //{
            //    if (VideoList1.VideosList != null)
            //    {
            //        if (((IEnumerable<BluePortal.Core.BusinessObjects.Video>)VideoList1.VideosList).Count() > 0)
            //        {
            //            vidSelected = ((IEnumerable<BluePortal.Core.BusinessObjects.Video>)VideoList1.VideosList).First().VID;
            //            ViewState["vidSelected"] = vidSelected;
            //        }
            //    }
            //    else
            //    {
            //        vidSelected = (Guid)ViewState["vidSelected"];
            //    }
            //}

            //literalSilverLight.Text = "PlayVideoID(\"" + vidSelected.ToString() + "\");";
            //VideoList1.videoSelected = vidSelected;
            //VideoProperties1.VideoId = vidSelected;
        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
        }
    }
}
